package com.cy.pj.sys.web.controller;

import com.cy.pj.sys.pojo.SysNotice;
import com.cy.pj.sys.service.SysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * 这个类我们称之为控制层对象的处理器(Handler),通过此对象处理
 * DispatcherServlet(核心控制器-Controller)分发的请求,具体的
 * 处理包括:
 * 1)定义请求url映射
 * 2)通过参数对象封装请求参数数据
 * 3)调用业务方法处理业务逻辑
 * 4)封装处理结果交给DispatcherServlet进行处理.
 */
@RequestMapping("/notice/")
@RestController
public class SysNoticeController {//这里写的controller又称之为handler
    @Autowired
    private SysNoticeService sysNoticeService;
    @RequestMapping("/doFindNotices")
    public List<SysNotice> doFindNotices(SysNotice notice){
        return sysNoticeService.findNotices(notice);
  /*
        此方法的返回值会交给DispatcherServlet，假如方法有 @ResponseBody注解修饰,
        DispatcherServlet会调用jackson api将方法的返回值转换为Json格式字符串，
        底层转换时会调用返回值对象的get方法，以get方法的方法名(去掉get单词)为key
        ,get方法的返回值为value来构建json格式字符串
        */
    }
    @RequestMapping("/notice/doUpdateNotice")
    public String doUpdateNotice(SysNotice notice){
       sysNoticeService.updateNotice(notice);
       return "notice Ok";
    }
    @RequestMapping("/notice/doFindById/{id}")
    @ResponseBody
    public SysNotice doFindById(@PathVariable Long id){
        return sysNoticeService.findById(id);
    }
    @RequestMapping("doSaveNotice")
    @ResponseBody
    public String doSaveNotice(SysNotice notice){
        sysNoticeService.saveNotice(notice);
        return "save ok";
    }
    @RequestMapping("doDeleteById")
    public int  ndoDeleteById(Long... ids){
        return sysNoticeService.deleteById(ids);
    }
}
